package juc.deadlock;

public class DeadLockDemo {

    private static Object res1 = new Object();
    private static Object res2 = new Object();


    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (res1) {
//                        Thread.sleep(1000L);
                    try {
                        // 释放当前锁
//                        this.wait(30000L);
                         Thread.sleep(1000L);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    synchronized (res2) {
                        System.out.println("拿到res2");
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (res2) {
                    try {
                        Thread.sleep(1000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (res1) {
                        System.out.println("拿到res1");
                    }
                }
            }
        }).start();

        System.out.println("结束了");


    }
}
